package com.labichaoka.chaoka.ui.home.fragment.my.withdraw;

import com.labichaoka.chaoka.entity.GetWithdrawInfo;
import com.labichaoka.chaoka.entity.GoWithdrawRequest;
import com.labichaoka.chaoka.entity.GoWithdrawResponse;
import com.labichaoka.chaoka.utils.ToastUtils;

public class WithdrawPresenterImpl implements WithdrawPresenter,WithdrawInteractor.OnFinishedListener {
    private WithdrawInteractor interactor;
    private WithdrawView view;

    public WithdrawPresenterImpl(WithdrawInteractor interactor, WithdrawView view) {
        this.interactor = interactor;
        this.view = view;
    }

    @Override
    public void getWithdrawInfo() {
        if (view!=null){
            view.showProgress();
        }
        interactor.getWithdrawInfo(this);
    }

    @Override
    public void goWithdraw(GoWithdrawRequest request) {
        if (view!=null){
            view.showProgress();
        }
        interactor.goWithdraw(request,this);
    }

    @Override
    public void onDestroy() {
        view=null;
    }

    @Override
    public void onGetWithdrawInfoSucc(GetWithdrawInfo response) {
        view.hideProgress();
        view.getWithdrawInfoCallback(response);

    }

    @Override
    public void onGetWithdrawInfoFailed() {
        view.hideProgress();
    }

    @Override
    public void onGoWithdrawSucc(GoWithdrawResponse response) {
        view.hideProgress();
        if (response.getCode().equals("-1")){
            ToastUtils.show(response.getMessage());
        }else{
            view.goWithdrawCallback(response);
        }
    }

    @Override
    public void onGoWithdrawFailed() {
        view.hideProgress();
    }
}
